//#include <numeric>
#include <valarray>
#include <iostream>
using namespace std;

template <class T>
class Sum
{
public:
    Sum():sum_(0){}
    T operator()(T element){
        sum_ += element;
        return sum_;
    }
private:
    T sum_;
};

template<class T, class Fun>
void apply2(valarray<T>& vala, Fun f)
{
    for(int i = 0; i < vala.size(); ++i){
        vala[i] = f(vala[i]);
    }
}

template<class T, class Fun>
valarray<T>  apply(valarray<T> vala, Fun f)
{
    valarray<T> ret = vala;
    
    for(int i = 0; i < vala.size(); ++i){
        ret[i] = f(vala[i]);
    }
    return ret;
}
int main()
{
    valarray<int> v1(1, 1000);
    Sum<int> sum;
    apply2(v1, sum);
    
    for(int i = 0; i < 1000; i++){
        std::cout << v1[i];
    }
    
    
}
